import jwt

class JWTE:
    def __init__(self):
        self.secrite_key='zxcvbnm'
    # 加密
    def jwt_en(self,data):
        return str(jwt.encode(data,self.secrite_key,algorithm='HS256'),encoding='utf8')
    # 对比
    def jwt_check(self,token):
        try:
            payload=jwt.decode(token,self.secrite_key,algorithms='HS256')
            newtoken=str(jwt.encode(payload,self.secrite_key,algorithm='HS256'),encoding='utf8')
            if newtoken==token:
                return True
        except:
            return False

    #解密
    def jwt_de(self,token):
        try:
            payload=jwt.decode(token,self.secrite_key,algorithms='HS256')
            return payload
        except:
            return None


my_jwt=JWTE()